<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="com.is.util.ParamUtil"%>
<%@page import="com.is.model.CourseScore"%>
<%@page import="com.is.control.CourseScoreControl"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@page import="com.is.control.ParamStuyearControl"%>
<%@page import="com.is.model.CourseClass"%>
<%@page import="com.is.control.CourseClassControl"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="../../resources/css/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../../resources/js/jquery-1.8.1.js"></script>
<script type="text/javascript" src="../../resources/js/jquery.artDialog.js"></script>
<title>录入成绩</title>
</head>
<body>
<%             

              //默认一次提交所有人的成绩
              int courseClassId = ParamUtil.getInt(request,"courseClassId");
              int size = ParamUtil.getInt(request,"size",0);
              int stuyear = ParamStuyearControl.getCurrentStuyearId();
              //System.out.print(courseClassId);
              CourseClass cc = CourseClassControl.getCourseClassById(courseClassId);
              if(cc!=null&&cc.getState()==0){
		              if(size>0){
		            	  List<CourseScore> css = new ArrayList<CourseScore>();
		            	  boolean flag=true;
		            	  for(int i=0;i<size;i++){
		            		  //System.out.print("SSS"+i);
		            		  int stuId=ParamUtil.getInt(request,"student"+i);
		            		  String attendanceScore = ParamUtil.getString(request,"attScore"+i,"0.0");
		            		  String dailyScore = ParamUtil.getString(request,"dailyScore"+i,"0.0");
		            		  String midtermScore = ParamUtil.getString(request,"midtermScore"+i,"0.0");
		            		  String finalScore = ParamUtil.getString(request,"finalScore"+i,"0.0");
		            		  String totalScore = ParamUtil.getString(request,"totalScore"+i,"0.0");
		            		  CourseScore cs = new CourseScore();
		            		  cs.setCourseClassId(courseClassId);
		            		  cs.setAttendanceScore(attendanceScore);
		            		  cs.setDailyScore(dailyScore);
		            		  cs.setFinalScore(finalScore);
		            		  cs.setTotalScore(totalScore);
		            		  cs.setMidtermScore(midtermScore);
		            		  cs.setStuId(stuId);
		            		  cs.setStuyear(stuyear);
		            		  css.add(cs);
		            	  }
		            	  if(CourseScoreControl.isInsertCourseScoreByStuyearAndCourseId(courseClassId, stuyear)){
		            	        if(CourseScoreControl.updateCourseScore(css)){
		            	        	CourseClassControl.updateStateById(courseClassId,1);
		            	             %>
			                      <script>
			                      $.dialog({
									    title: '成绩录入',
									    content: '系统已成功修改学生成绩',
									    icon: 'succeed',
									    ok: function(){
			                    	  		window.location.href='score_go.jsp';
									    }
									});
			                     // alert("系统已成功修改学生成绩");
			                      //window,location.href="../temp.jsp";
			                      </script>
			                      <%
			            	    }else{
			            		  %>
			                      <script>
			                      $.dialog({
									    title: '成绩录入',
									    content: '抱歉，系统出现错误或您录入的信息有误，本次录入信息均无效，请重试',
									    icon: 'warning',
									    ok: function(){
			                    	  			history.go(-1);
									    }
									});
			                      //alert("抱歉，系统出现错误或您录入的信息有误，本次录入信息均无效，请重试");
			                      //history.go(-1);
			                      </script>
			                      <%
		            	         }
		            	  }else{
			            	  if(CourseScoreControl.insertCourseScore(css)){
			            		  CourseClassControl.updateStateById(courseClassId,1);
			            		  %>
			                      <script>
			                      $.dialog({
									    title: '成绩录入',
									    content: '系统已成功录入学生成绩',
									    icon: 'succeed',
									    ok: function(){
			                    	  		window.location.href='score_go.jsp';
									    }
									});
			                     // alert("系统已成功录入成绩");
			                      //window,location.href="../temp.jsp";
			                      </script>
			                      <%
			            	  }else{
			            		  %>
			                      <script>
			                      $.dialog({
									    title: '成绩录入',
									    content: '抱歉，系统出现错误或您录入的信息有误，本次录入信息均无效，请重试',
									    icon: 'warning',
									    ok: function(){
			                    	  			history.go(-1);
									    }
									});
			                      //alert("抱歉，系统出现错误或您录入的信息有误，本次录入信息均无效，请重试");
			                      //history.go(-1);
			                      </script>
			                      <%
			            	  }
		              }
		            }
              }else{
            	  %>
                  <script>
                  $.dialog({
					    title: '成绩录入',
					    content: '您已经提交过成绩，暂时无法修改，请联系管理员',
					    icon: 'warning',
					    ok: function(){
                	          window.location.href='score_go.jsp';
					    }
					});
					</script>
                  <%
              }

%>
</body>
</html>